package com.ruoyi.system.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

/**
 * 登录相关工具类
 */
@Slf4j
public class EncryptUtil {
//    /**
//     * 生成加密密码
//     * @param pwd  pwd
//     * @param salt salt
//     * @return mdPs
//     */
//    public static String encryptPwd(String pwd, String salt){
//        MD5 md5 = new MD5();
//        String ps = pwd + salt;
//        return md5.getMD5ofStr(ps);
//    }

    public static String getUserNoFromToken(){
        HttpServletRequest request =
                ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
        return JwtUtil.getUserNoByToken(request);
    }

    public static Long getUserIdFromToken(){
        HttpServletRequest request =
                ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
        return JwtUtil.getUserIdByToken(request);
    }

    public static String getUserPhoneFromToken(){
        HttpServletRequest request =
                ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
        return JwtUtil.getUserPhoneByToken(request);
    }

    public static String getUserNameFromToken(){
        HttpServletRequest request =
                ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
        return JwtUtil.getUserNameByToken(request);
    }

    public static void main(String[] args) {
//        String e095e21ecf414080 = encryptPwd("123456", "MG9nw7qkoZwIoQQu");
//        System.out.println(e095e21ecf414080);
    }
}
